local spr = app.activeSprite
if not spr then
  return app.alert("There is no active sprite")
end


local info = debug.getinfo(1);
local str = info.source:sub(2)
local script_path = str:match("(.*\\)")

local handle = io.popen('MODE con: COLS=16 LINES=1 &  ' .. script_path .. 'ColorPicker.exe')
local color = handle:read("*a")
handle:close()

-- os.execute('del '.. script_path .. "color.txt")
-- os.execute('start '.. script_path .. "ColorPicker.exe -f")
-- local file = io.open(script_path .. "color.txt", "r")
-- while file == nil do
--   file = io.open(script_path .. "color.txt", "r")
-- end
-- io.input(file)
-- local color = io.read()
-- io.close()
-- os.execute('del '.. script_path .. "color.txt")
-- print("color", color);

if (color and color ~= '') then
  local r, g, b = string.match(color, "(.*)%,(.*)%,(.*)")

  app.transaction(function()
      app.bgColor = Color{ r=r, g=g, b=b }
  end)
end
